package com.ruoyi.marketing.service.impl;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import io.swagger.models.auth.In;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.marketing.mapper.ActivityMapper;
import com.ruoyi.marketing.domain.Activity;
import com.ruoyi.marketing.service.IActivityService;

@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> implements IActivityService {

    /**
     * 查询营销活动列表
     *
     * @param activity 营销活动
     * @return 营销活动
     */
    @Override
    public List<Activity> selectActivityList(Activity activity) {
        List<Activity> activities = getBaseMapper().selectActivityList(activity);
        return activities;
    }

    @SneakyThrows
    @Override
    public boolean save(Activity entity) {
        Integer number = entity.getNumber();
        Integer[] a = new Integer[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        List<Integer> list = Arrays.asList(a);
        if (!list.contains(number)) {
           throw   new  RuntimeException("输入的数字有误");
        }
        entity.setValidTime(entity.getMinTime() + "至" + entity.getMaxTime());
        Date date = new Date();
        if (entity.getMinTime().after(date) && entity.getMaxTime().before(date)) {
            entity.setState(1);
        } else {
            entity.setState(2);
        }
        return super.save(entity);
    }


}
